﻿// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using NSQL.Sharpen;

namespace NSQL.Expressions.Functions
{
    public class PadFunction : BaseExpression, IPadFunction
    {
        public IStringExpression Text { get; set; }
        public IConstantIntegerExpression Length { get; set; }
        public IConstantStringExpression PaddingText { get; set; }
        public PaddingType Type { get; set; }

        public PadFunction(IExpression text, PaddingType type, IConstantIntegerExpression length, IConstantStringExpression paddingText =null)
        {
            Text = (IStringExpression) text;
            Type = type;
            Length = length;
            PaddingText = paddingText;
        }

        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);
        public override void Accept(IExpressionVisitor visitor) => visitor.Visit(this);
        public override bool IsValid => Text.IsValid && Length.IsValid && PaddingText.IsValid;
        protected override IExpression DeepCopy()
        {
            return new PadFunction(Text.DeepClone(), Type, Length.DeepClone(), PaddingText.DeepClone())
            {
                Tag = Tag
            };
        }
    }
}